package com.woniuxy.core.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.entity.AllUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.entity.UserCoupon;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author nanqiao
 * @description 针对表【all_user(用户基础信息表)】的数据库操作Mapper
 */
@Mapper
public interface AllUserMapper extends BaseMapper<AllUser> {

    AllUser getUserById(Long userId);

    @Select("select * from user_coupon where id = #{couponId} and status =1")
    UserCoupon getCoupon(Integer couponId);

    @Update("update user_coupon set status = 2 where id = #{id}")
    Integer lockCoupon(Integer id);

    void addCoinToUser(@Param("userId") Long userId);

    int deductBalance(@Param("userId") Long userId, @Param("amount") BigDecimal amount);

    @Update("update all_user set balance = balance + #{amount} where user_id = #{sellerId}")
    int increaseBalance(@Param("sellerId") Long sellerId, @Param("amount") BigDecimal amount);

    /**
     * 随机获取用户ID列表
     *
     * @param limit 随机获取的用户数量
     * @return 用户ID列表
     */
    List<Long> listRandomUserIds(int limit);
}




